package com.android.equipment.dao.operate;

import com.android.equipment.ObjectBox;
import com.android.equipment.dao.DeviceModelAlamConfig;
import com.android.equipment.dao.DeviceModelAlamConfig_;

import java.util.ArrayList;
import java.util.List;

import io.objectbox.Box;
import io.objectbox.query.QueryBuilder;

public class DaoDeviceModelAlamConfig {
    static Box<DeviceModelAlamConfig> deviceModelAlamConfigBox;

    private static DaoDeviceModelAlamConfig instance;

    private DaoDeviceModelAlamConfig() {
    }

    public static DaoDeviceModelAlamConfig getInstance() {
        if (instance == null) {
            instance = new DaoDeviceModelAlamConfig();
            deviceModelAlamConfigBox = ObjectBox.get().boxFor(DeviceModelAlamConfig.class);
        }
        return instance;
    }


    public void addDefaultDeviceModelAlamConfig(String device_model) {
        List<DeviceModelAlamConfig> list = new ArrayList<>();
        list.add(new DeviceModelAlamConfig(device_model, "pow", "开关机状态", 1, "开机",0));
        list.add(new DeviceModelAlamConfig(device_model, "check", "自检正常", 1, "自检异常",0));
        list.add(new DeviceModelAlamConfig(device_model, "alm1", "围杆带挂钩", 1, "围杆带挂钩恢复",1));
        list.add(new DeviceModelAlamConfig(device_model, "alm2", "围杆带状态", 1, "围杆带状态恢复",1));
        list.add(new DeviceModelAlamConfig(device_model, "alm3", "S0S紧急求救", 1, "S0S紧急求救恢复",1));
        list.add(new DeviceModelAlamConfig(device_model, "alm4", "设备状态", 1, "设备状态恢复",1));
        list.add(new DeviceModelAlamConfig(device_model, "walm1", "保险绳挂钩", 1, "保险绳挂钩恢复",1));
        list.add(new DeviceModelAlamConfig(device_model, "walm2", "高挂抵用", 1, "高挂抵用恢复",1));
        list.add(new DeviceModelAlamConfig(device_model, "walm3", "绳缓冲包", 1, "绳缓冲包恢复",1));
        list.add(new DeviceModelAlamConfig(device_model, "walm4", "围杆带挂钩", 1, "围杆带挂钩恢复",1));
        list.add(new DeviceModelAlamConfig(device_model, "walm5", "围杆带状态", 1, "围杆带状态恢复",1));
        list.add(new DeviceModelAlamConfig(device_model, "gps", "定位", 1, "",0));
        list.add(new DeviceModelAlamConfig(device_model, "sbat1", "无线开关电源1", 1, "",2));
        list.add(new DeviceModelAlamConfig(device_model, "sbat2", "无线开关电源2", 1, "",2));
        list.add(new DeviceModelAlamConfig(device_model, "sbat3", "无线开关电源3", 1, "",2));
        list.add(new DeviceModelAlamConfig(device_model, "sbat4", "无线开关电源4", 1, "",2));
        list.add(new DeviceModelAlamConfig(device_model, "sbat5", "无线开关电源5", 1, "",2));
        list.add(new DeviceModelAlamConfig(device_model, "high", "高度", 1, "",2));

        deviceModelAlamConfigBox.put(list);
    }

    public DeviceModelAlamConfig getDeviceModelAlamConfig(String device_model, String node) {
        return deviceModelAlamConfigBox.query().
                equal(DeviceModelAlamConfig_.device_model, device_model, QueryBuilder.StringOrder.CASE_INSENSITIVE).
                equal(DeviceModelAlamConfig_.node, node, QueryBuilder.StringOrder.CASE_INSENSITIVE)
                .build().
                findUnique();
    }

    public void updateDeviceModelAlamConfig(DeviceModelAlamConfig deviceModelAlamConfig) {
        deviceModelAlamConfigBox.put(deviceModelAlamConfig);
    }

    public DeviceModelAlamConfig getDeviceModelAlamConfigById(long id) {
        return deviceModelAlamConfigBox.get(id);
    }
}
